﻿<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>应用安装</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
</head>
<body>
  <div class="layui-row" style="padding: 20px 30px 0 0;">
      <div class="layui-col-md12" id="uploadfile">
        <div class="layui-form-item" >
          <label class="layui-form-label">上传文件：</label>
          <div class="layui-input-inline">
           <div class="layui-upload">
              <button type="button" class="layui-btn" id="btn_upload_change"><i class="layui-icon"></i>选择安装文件</button>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form" lay-filter="form-add" id="form-add" style="display:none;">
        <input type="hidden" name="path" value="" />
        <div class="layui-form-item">
          <label class="layui-form-label">应用名称：</label>
          <div class="layui-input-inline">
            <input type="text" name="name" style="width:400px;" value="" class="layui-input" readonly>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">安装路径：</label>
          <div class="layui-input-inline">
            <input type="text" name="installpath" lay-verify="required" style="width:400px;" value="" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">应用标识：</label>
          <div class="layui-input-inline">
            <input type="text" name="appkey" lay-verify="required" style="width:400px;" value="" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">应用版本：</label>
          <div class="layui-input-inline">
            <input type="text" name="version" style="width:400px;" value="" class="layui-input" readonly>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">应用作者：</label>
          <div class="layui-input-inline">
            <input type="text" name="author" style="width:400px;" value="" class="layui-input" readonly>
          </div>
        </div>
        
        <div class="layui-form-item">
          <label class="layui-form-label">应用简介：</label>
          <div class="layui-input-inline">
            <textarea name="intro" style="width:400px;" class="layui-textarea"></textarea>
          </div>
        </div>
        <div class="layui-form-item layui-hide">
          <input type="button" lay-submit lay-filter="btn_submit" id="btn_submit" value="确定">
        </div>
      </div>
  </div>
  <script src="/plugins/layui/layui.js"></script>
  <script>
  layui.config({
    base: '/plugins/layuiadmin/' 
  }).extend({
    index: 'lib/index'
  }).use(['index', 'form','upload'], function(){
    var $ = layui.$, form = layui.form, router = layui.router(),upload = layui.upload;
    upload.render({
      elem: '#btn_upload_change'
      ,url: 'app_install?action=upload'
      ,accept: 'file'
      , exts: 'zip|fpk'
      ,choose: function(){
        layer.load();
      }
      , done: function (res) {
          layer.closeAll('loading'); 
          if (res.code == 0) {
              form.val("form-add", res.data);
              $("#uploadfile").hide();
              $("#form-add").show();
          }
          else {
              layer.alert(res.msg);
          }
      }
    });

    form.on('submit(btn_submit)', function (data) {
      layer.load();
      var field = data.field; 
      var index = parent.layer.getFrameIndex(window.name); 
      $.ajax({
            type: "post",
            url: "app_install?action=install",
            data: field,
            dataType: "json",
            success: function (res) {
              layer.closeAll('loading'); 
              if (res.code == 0)
              {
                layer.msg(res.msg,{time:1*1000},function(){
                    parent.layer.close(index);
                    parent.GetFirstList();
                });
              }
              else
              {
                 layer.alert(res.msg);
              }
            }
      });
    });
  })
  </script>
</body>
</html>